home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14440 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  31 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!smryan
  3. From: smryan@netcom.com (@#$%!?!)
  4. Subject: Re: saving system()'s output to a C variable?
  5. Message-ID: <smryanDpuDMI.Cyq@netcom.com>
  6. Organization: The Programmer formerly known as S M Ryan
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. References: <96104.233554U61441@uicvm.uic.edu>
  9. Date: Sun, 14 Apr 1996 07:47:06 GMT
  10. Sender: smryan@netcom13.netcom.com
  11.  
  12. :   Is it possible to save the output of the system() command to
  13. : a C variable? For example, when I have the line system("date")
  14. : in my C program, I want the output of this command to go to a
  15. : C variable (e.g. char array) instead of going on the stdout.
  16. : Please send me email at swaheed@uic.edu
  17.  
  18. If your system has pipes or the like, you can use popen/pclose.
  19. Otherwise, just the save the output to a file and then read the
  20. file.
  21.  
  22.     system("date >xx");
  23.     f = fopen("xx","r");
  24.     fgets(array,size,f);
  25.     fclose(f);
  26. -- 
  27. The Queen, amused, in quiet power,         | smryan@netcom.com  PO Box 1563
  28. will draw the son to darkenned bower.      |          Cupertino, California
  29. Her face is fair, her fragrance rare,      | (xxx)xxx-xxxx            95015
  30. with woven webs for wayward flower.        |         I don't use no smileys
  31.